package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.AgedmallStoreDeviceMapper;
import org.linlinjava.litemall.db.dao.AgedmallStoreMapper;
import org.linlinjava.litemall.db.dao.app.AppStoreMapper;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.util.AgedmallStoreDeviceConstant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class AgedmallStoreDeviceService {

    @Resource
    private AgedmallStoreDeviceMapper agedmallStoreDeviceMapper;

    public void add(AgedmallStoreDevice agedmallStoreDevice) {
        agedmallStoreDevice.setAddTime(LocalDateTime.now());
        agedmallStoreDevice.setUpdateTime(LocalDateTime.now());
        agedmallStoreDevice.setDeleted(false);
        agedmallStoreDeviceMapper.insert(agedmallStoreDevice);
    }

    public void delete(Integer id) {
        agedmallStoreDeviceMapper.logicalDeleteByPrimaryKey(id);
    }

    public AgedmallStoreDevice queryByDeviceIdAndStoreId(Integer deviceId, Integer storeId) {
        AgedmallStoreDeviceExample example = new AgedmallStoreDeviceExample();
        example.createCriteria().andDeletedEqualTo(false)
                .andDeviceCodeEqualTo(deviceId+"")
                .andStoreIdEqualTo(storeId);
        return agedmallStoreDeviceMapper.selectOneByExample(example);
    }

    public AgedmallStoreDevice queryLockerByStoreId(Integer storeId) {
        AgedmallStoreDeviceExample example = new AgedmallStoreDeviceExample();
        example.createCriteria().andDeletedEqualTo(false)
                .andStoreIdEqualTo(storeId)
                .andDeviceTypeEqualTo(AgedmallStoreDeviceConstant.TYPE_LOCKER);
        return agedmallStoreDeviceMapper.selectOneByExample(example);
    }

    public AgedmallStoreDevice queryByDeviceIdAndType(Integer deviceId, Integer type) {
        AgedmallStoreDeviceExample example = new AgedmallStoreDeviceExample();
        example.createCriteria().andDeletedEqualTo(false)
                .andDeviceCodeEqualTo(deviceId+"")
                .andDeviceTypeEqualTo(type);
        return agedmallStoreDeviceMapper.selectOneByExample(example);
    }
}
